define ['fizz', 'i18n!nls/messages', 'template/paginator'],  (fizz, messages, templatePaginator) ->

  fizz.hbs.registerHelper 'paginator', (pageCollection) ->
    new fizz.hbs.SafeString(templatePaginator {messages: messages, collection: pageCollection})

  fizz.hbs.registerHelper 'buttonSelect', (id, selectedIds) ->
    if _.contains(selectedIds, id)
      new fizz.hbs.SafeString('<button type="button" class="btn select selected" data-id="' + id + '"><i class="fa fa-check-square-o"></i></button>')
    else
      new fizz.hbs.SafeString('<button type="button" class="btn select" data-id="' + id + '"><i class="fa fa-check-square-o"></i></button>')

  fizz.hbs.registerHelper 'buttonAdd', ->
    new fizz.hbs.SafeString('<button type="button" class="btn add"><i class="fa fa-plus"></i></button>')

  fizz.hbs.registerHelper 'buttonsSearch', ->
    new fizz.hbs.SafeString('<span class="input-group-btn"><button type="submit" class="btn submit"><i class="fa fa-search"></i></button><button type="button" class="btn clean"><i class="fa fa-eraser"></i></button></span>')

  fizz.hbs.registerHelper 'buttonValidate', ->
    new fizz.hbs.SafeString('<button type="button" class="btn validate"><i class="fa fa-check"></i></button>')

  fizz.hbs.registerHelper 'buttonSubmit', ->
    new fizz.hbs.SafeString('<button type="submit" class="btn submit"><i class="fa fa-check"></i></button>')
    
  fizz.hbs.registerHelper 'buttonLogin', ->
    new fizz.hbs.SafeString('<button type="submit" class="btn submit"><i class="fa fa-sign-in"></i></button>')

  fizz.hbs.registerHelper 'buttonReturn', ->
    new fizz.hbs.SafeString('<button type="button" class="btn return"><i class="fa fa-arrow-left"></i></button>')

  fizz.hbs.registerHelper 'buttonCancel', ->
    new fizz.hbs.SafeString('<button type="button" class="btn cancel"><i class="fa fa-times"></i></button>')

  fizz.hbs.registerHelper 'buttonNothing', ->
    new fizz.hbs.SafeString('<button type="button" class="btn nothing"><i class="fa fa-square-o"></i></button>')

  fizz.hbs.registerHelper 'buttonView', (id) ->
    new fizz.hbs.SafeString('<button type="button" class="btn view" data-id="' + id + '"><i class="fa fa-eye"></i></button>')

  fizz.hbs.registerHelper 'buttonEdit', (id) ->
    new fizz.hbs.SafeString('<button type="button" class="btn edit" data-id="' + id + '"><i class="fa fa-edit"></i></button>')

  fizz.hbs.registerHelper 'buttonDelete', (id) ->
    new fizz.hbs.SafeString('<button type="button" class="btn delete" data-id="' + id + '"><i class="fa fa-trash-o"></i></button>')

  fizz.hbs.registerHelper 'buttonsList', (action) ->
    html = '<span class="btn-group">'
    if 'view' is action
      html += fizz.hbs.helpers['buttonAdd'].call(@, action)
    else if 'select' is action
      html += fizz.hbs.helpers['buttonCancel'].call(@, action) + fizz.hbs.helpers['buttonNothing'].call(@, action)
    else if 'multiselect' is action
      html += fizz.hbs.helpers['buttonCancel'].call(@, action) + fizz.hbs.helpers['buttonValidate'].call(@, action)
    html += '</span>'
    new fizz.hbs.SafeString(html)

  fizz.hbs.registerHelper 'buttonsItem', (action, id, selectedIds) ->
    html = '<span class="btn-group">'
    if 'view' is action
      html += fizz.hbs.helpers['buttonView'].call(@, id) + fizz.hbs.helpers['buttonEdit'].call(@, id) + fizz.hbs.helpers['buttonDelete'].call(@, id)
    else if 'select' is action
      html += fizz.hbs.helpers['buttonSelect'].call(@, id)
    else if 'multiselect' is action
      html += fizz.hbs.helpers['buttonSelect'].call(@, id, selectedIds)
    html += '</span>'
    new fizz.hbs.SafeString(html)

  fizz.hbs.registerHelper 'buttonsCrud', (action) ->
    html = '<span class="btn-group">'
    if 'add' is action or 'edit' is action or 'delete' is action
      html += fizz.hbs.helpers['buttonCancel'].call(@) + fizz.hbs.helpers['buttonSubmit'].call(@)
    else if 'view' is action
      html += fizz.hbs.helpers['buttonReturn'].call(@)
    html += '</span>'
    new fizz.hbs.SafeString(html)

  fizz.hbs
